{
 "nbformat": 4,
 "nbformat_minor": 2,
 "metadata": {
  "language_info": {
   "name": "python",
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "version": "3.7.7-final"
  },
  "orig_nbformat": 2,
  "file_extension": ".py",
  "mimetype": "text/x-python",
  "name": "python",
  "npconvert_exporter": "python",
  "pygments_lexer": "ipython3",
  "version": 3,
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3"
  }
 },
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = pd.read_excel('./meal_order_detail.xlsx')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "      detail_id  order_id  dishes_id  logicprn_name  parent_class_name  \\\n0          2956       417     610062            NaN                NaN   \n1          2958       417     609957            NaN                NaN   \n2          2961       417     609950            NaN                NaN   \n3          2966       417     610038            NaN                NaN   \n4          2968       417     610003            NaN                NaN   \n...         ...       ...        ...            ...                ...   \n2774       6750       774     610011            NaN                NaN   \n2775       6742       774     609996            NaN                NaN   \n2776       6756       774     609949            NaN                NaN   \n2777       6763       774     610014            NaN                NaN   \n2778       6764       774     610017            NaN                NaN   \n\n            dishes_name  itemis_add  counts  amounts  cost  \\\n0                  蒜蓉生蚝           0       1       49   NaN   \n1     蒙古烤羊腿\\r\\n\\r\\n\\r\\n           0       1       48   NaN   \n2                  大蒜苋菜           0       1       30   NaN   \n3                 芝麻烤紫菜           0       1       25   NaN   \n4                   蒜香包           0       1       13   NaN   \n...                 ...         ...     ...      ...   ...   \n2774              白饭/大碗           0       1       10   NaN   \n2775                牛尾汤           0       1       40   NaN   \n2776             意文柠檬汁            0       1       13   NaN   \n2777               金玉良缘           0       1       30   NaN   \n2778               酸辣藕丁           0       1       33   NaN   \n\n        place_order_time  discount_amt  discount_reason  kick_back  \\\n0    2016-08-01 11:05:36           NaN              NaN        NaN   \n1    2016-08-01 11:07:07           NaN              NaN        NaN   \n2    2016-08-01 11:07:40           NaN              NaN        NaN   \n3    2016-08-01 11:11:11           NaN              NaN        NaN   \n4    2016-08-01 11:11:30           NaN              NaN        NaN   \n...                  ...           ...              ...        ...   \n2774 2016-08-10 21:56:24           NaN              NaN        NaN   \n2775 2016-08-10 21:56:48           NaN              NaN        NaN   \n2776 2016-08-10 22:01:52           NaN              NaN        NaN   \n2777 2016-08-10 22:03:58           NaN              NaN        NaN   \n2778 2016-08-10 22:04:30           NaN              NaN        NaN   \n\n      add_inprice  add_info  bar_code      picture_file  emp_id  \n0               0       NaN       NaN  caipu/104001.jpg    1442  \n1               0       NaN       NaN  caipu/202003.jpg    1442  \n2               0       NaN       NaN  caipu/303001.jpg    1442  \n3               0       NaN       NaN  caipu/105002.jpg    1442  \n4               0       NaN       NaN  caipu/503002.jpg    1442  \n...           ...       ...       ...               ...     ...  \n2774            0       NaN       NaN  caipu/601005.jpg    1138  \n2775            0       NaN       NaN  caipu/201006.jpg    1138  \n2776            0       NaN       NaN  caipu/404005.jpg    1138  \n2777            0       NaN       NaN  caipu/302003.jpg    1138  \n2778            0       NaN       NaN  caipu/302006.jpg    1138  \n\n[2779 rows x 19 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>detail_id</th>\n      <th>order_id</th>\n      <th>dishes_id</th>\n      <th>logicprn_name</th>\n      <th>parent_class_name</th>\n      <th>dishes_name</th>\n      <th>itemis_add</th>\n      <th>counts</th>\n      <th>amounts</th>\n      <th>cost</th>\n      <th>place_order_time</th>\n      <th>discount_amt</th>\n      <th>discount_reason</th>\n      <th>kick_back</th>\n      <th>add_inprice</th>\n      <th>add_info</th>\n      <th>bar_code</th>\n      <th>picture_file</th>\n      <th>emp_id</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>2956</td>\n      <td>417</td>\n      <td>610062</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>蒜蓉生蚝</td>\n      <td>0</td>\n      <td>1</td>\n      <td>49</td>\n      <td>NaN</td>\n      <td>2016-08-01 11:05:36</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>caipu/104001.jpg</td>\n      <td>1442</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>2958</td>\n      <td>417</td>\n      <td>609957</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>蒙古烤羊腿\\r\\n\\r\\n\\r\\n</td>\n      <td>0</td>\n      <td>1</td>\n      <td>48</td>\n      <td>NaN</td>\n      <td>2016-08-01 11:07:07</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>caipu/202003.jpg</td>\n      <td>1442</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>2961</td>\n      <td>417</td>\n      <td>609950</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>大蒜苋菜</td>\n      <td>0</td>\n      <td>1</td>\n      <td>30</td>\n      <td>NaN</td>\n      <td>2016-08-01 11:07:40</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>caipu/303001.jpg</td>\n      <td>1442</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>2966</td>\n      <td>417</td>\n      <td>610038</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>芝麻烤紫菜</td>\n      <td>0</td>\n      <td>1</td>\n      <td>25</td>\n      <td>NaN</td>\n      <td>2016-08-01 11:11:11</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>caipu/105002.jpg</td>\n      <td>1442</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>2968</td>\n      <td>417</td>\n      <td>610003</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>蒜香包</td>\n      <td>0</td>\n      <td>1</td>\n      <td>13</td>\n      <td>NaN</td>\n      <td>2016-08-01 11:11:30</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>caipu/503002.jpg</td>\n      <td>1442</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>2774</th>\n      <td>6750</td>\n      <td>774</td>\n      <td>610011</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>白饭/大碗</td>\n      <td>0</td>\n      <td>1</td>\n      <td>10</td>\n      <td>NaN</td>\n      <td>2016-08-10 21:56:24</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>caipu/601005.jpg</td>\n      <td>1138</td>\n    </tr>\n    <tr>\n      <th>2775</th>\n      <td>6742</td>\n      <td>774</td>\n      <td>609996</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>牛尾汤</td>\n      <td>0</td>\n      <td>1</td>\n      <td>40</td>\n      <td>NaN</td>\n      <td>2016-08-10 21:56:48</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>caipu/201006.jpg</td>\n      <td>1138</td>\n    </tr>\n    <tr>\n      <th>2776</th>\n      <td>6756</td>\n      <td>774</td>\n      <td>609949</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>意文柠檬汁</td>\n      <td>0</td>\n      <td>1</td>\n      <td>13</td>\n      <td>NaN</td>\n      <td>2016-08-10 22:01:52</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>caipu/404005.jpg</td>\n      <td>1138</td>\n    </tr>\n    <tr>\n      <th>2777</th>\n      <td>6763</td>\n      <td>774</td>\n      <td>610014</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>金玉良缘</td>\n      <td>0</td>\n      <td>1</td>\n      <td>30</td>\n      <td>NaN</td>\n      <td>2016-08-10 22:03:58</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>caipu/302003.jpg</td>\n      <td>1138</td>\n    </tr>\n    <tr>\n      <th>2778</th>\n      <td>6764</td>\n      <td>774</td>\n      <td>610017</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>酸辣藕丁</td>\n      <td>0</td>\n      <td>1</td>\n      <td>33</td>\n      <td>NaN</td>\n      <td>2016-08-10 22:04:30</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>0</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>caipu/302006.jpg</td>\n      <td>1138</td>\n    </tr>\n  </tbody>\n</table>\n<p>2779 rows × 19 columns</p>\n</div>"
     },
     "metadata": {},
     "execution_count": 5
    }
   ],
   "source": [
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_gb=data[['order_id','counts','amounts']].groupby(by='order_id')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "          counts  amounts\norder_id                 \n137            6        6\n165           18       18\n166            5        5\n171            7        7\n177            4        4\n...          ...      ...\n1309          13       13\n1314          12       12\n1317          18       18\n1319           9        9\n1323          15       15\n\n[278 rows x 2 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>counts</th>\n      <th>amounts</th>\n    </tr>\n    <tr>\n      <th>order_id</th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>137</th>\n      <td>6</td>\n      <td>6</td>\n    </tr>\n    <tr>\n      <th>165</th>\n      <td>18</td>\n      <td>18</td>\n    </tr>\n    <tr>\n      <th>166</th>\n      <td>5</td>\n      <td>5</td>\n    </tr>\n    <tr>\n      <th>171</th>\n      <td>7</td>\n      <td>7</td>\n    </tr>\n    <tr>\n      <th>177</th>\n      <td>4</td>\n      <td>4</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>1309</th>\n      <td>13</td>\n      <td>13</td>\n    </tr>\n    <tr>\n      <th>1314</th>\n      <td>12</td>\n      <td>12</td>\n    </tr>\n    <tr>\n      <th>1317</th>\n      <td>18</td>\n      <td>18</td>\n    </tr>\n    <tr>\n      <th>1319</th>\n      <td>9</td>\n      <td>9</td>\n    </tr>\n    <tr>\n      <th>1323</th>\n      <td>15</td>\n      <td>15</td>\n    </tr>\n  </tbody>\n</table>\n<p>278 rows × 2 columns</p>\n</div>"
     },
     "metadata": {},
     "execution_count": 12
    }
   ],
   "source": [
    "data_gb.count()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "          counts  amounts\norder_id                 \n137            9      194\n165           21      953\n166            7      241\n171           10      254\n177            4      137\n...          ...      ...\n1309          15      443\n1314          12      508\n1317          18     1210\n1319           9      610\n1323          15      764\n\n[278 rows x 2 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>counts</th>\n      <th>amounts</th>\n    </tr>\n    <tr>\n      <th>order_id</th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>137</th>\n      <td>9</td>\n      <td>194</td>\n    </tr>\n    <tr>\n      <th>165</th>\n      <td>21</td>\n      <td>953</td>\n    </tr>\n    <tr>\n      <th>166</th>\n      <td>7</td>\n      <td>241</td>\n    </tr>\n    <tr>\n      <th>171</th>\n      <td>10</td>\n      <td>254</td>\n    </tr>\n    <tr>\n      <th>177</th>\n      <td>4</td>\n      <td>137</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>1309</th>\n      <td>15</td>\n      <td>443</td>\n    </tr>\n    <tr>\n      <th>1314</th>\n      <td>12</td>\n      <td>508</td>\n    </tr>\n    <tr>\n      <th>1317</th>\n      <td>18</td>\n      <td>1210</td>\n    </tr>\n    <tr>\n      <th>1319</th>\n      <td>9</td>\n      <td>610</td>\n    </tr>\n    <tr>\n      <th>1323</th>\n      <td>15</td>\n      <td>764</td>\n    </tr>\n  </tbody>\n</table>\n<p>278 rows × 2 columns</p>\n</div>"
     },
     "metadata": {},
     "execution_count": 13
    }
   ],
   "source": [
    "data_gb.sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "           counts        amounts\nsum   3088.000000  125992.000000\nmean     1.111191      45.337172",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>counts</th>\n      <th>amounts</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>sum</th>\n      <td>3088.000000</td>\n      <td>125992.000000</td>\n    </tr>\n    <tr>\n      <th>mean</th>\n      <td>1.111191</td>\n      <td>45.337172</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "metadata": {},
     "execution_count": 15
    }
   ],
   "source": [
    "import numpy as np\n",
    "data[['counts','amounts']].agg([np.sum,np.mean])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "      counts        amounts\nmean     NaN      45.337172\nsum   3088.0  125992.000000",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>counts</th>\n      <th>amounts</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>mean</th>\n      <td>NaN</td>\n      <td>45.337172</td>\n    </tr>\n    <tr>\n      <th>sum</th>\n      <td>3088.0</td>\n      <td>125992.000000</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "metadata": {},
     "execution_count": 18
    }
   ],
   "source": [
    "data[['counts','amounts']].agg({'counts':np.sum,'amounts':[np.sum,np.mean]})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "          counts  amounts\norder_id                 \n137            9      194\n165           21      953\n166            7      241\n171           10      254\n177            4      137\n...          ...      ...\n1309          15      443\n1314          12      508\n1317          18     1210\n1319           9      610\n1323          15      764\n\n[278 rows x 2 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>counts</th>\n      <th>amounts</th>\n    </tr>\n    <tr>\n      <th>order_id</th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>137</th>\n      <td>9</td>\n      <td>194</td>\n    </tr>\n    <tr>\n      <th>165</th>\n      <td>21</td>\n      <td>953</td>\n    </tr>\n    <tr>\n      <th>166</th>\n      <td>7</td>\n      <td>241</td>\n    </tr>\n    <tr>\n      <th>171</th>\n      <td>10</td>\n      <td>254</td>\n    </tr>\n    <tr>\n      <th>177</th>\n      <td>4</td>\n      <td>137</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>1309</th>\n      <td>15</td>\n      <td>443</td>\n    </tr>\n    <tr>\n      <th>1314</th>\n      <td>12</td>\n      <td>508</td>\n    </tr>\n    <tr>\n      <th>1317</th>\n      <td>18</td>\n      <td>1210</td>\n    </tr>\n    <tr>\n      <th>1319</th>\n      <td>9</td>\n      <td>610</td>\n    </tr>\n    <tr>\n      <th>1323</th>\n      <td>15</td>\n      <td>764</td>\n    </tr>\n  </tbody>\n</table>\n<p>278 rows × 2 columns</p>\n</div>"
     },
     "metadata": {},
     "execution_count": 20
    }
   ],
   "source": [
    "data_gb.agg(np.sum)\n",
    "data_gb.sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "         counts amounts           \n            sum     sum       mean\norder_id                          \n137           9     194  32.333333\n165          21     953  52.944444\n166           7     241  48.200000\n171          10     254  36.285714\n177           4     137  34.250000\n...         ...     ...        ...\n1309         15     443  34.076923\n1314         12     508  42.333333\n1317         18    1210  67.222222\n1319          9     610  67.777778\n1323         15     764  50.933333\n\n[278 rows x 3 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead tr th {\n        text-align: left;\n    }\n\n    .dataframe thead tr:last-of-type th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr>\n      <th></th>\n      <th>counts</th>\n      <th colspan=\"2\" halign=\"left\">amounts</th>\n    </tr>\n    <tr>\n      <th></th>\n      <th>sum</th>\n      <th>sum</th>\n      <th>mean</th>\n    </tr>\n    <tr>\n      <th>order_id</th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>137</th>\n      <td>9</td>\n      <td>194</td>\n      <td>32.333333</td>\n    </tr>\n    <tr>\n      <th>165</th>\n      <td>21</td>\n      <td>953</td>\n      <td>52.944444</td>\n    </tr>\n    <tr>\n      <th>166</th>\n      <td>7</td>\n      <td>241</td>\n      <td>48.200000</td>\n    </tr>\n    <tr>\n      <th>171</th>\n      <td>10</td>\n      <td>254</td>\n      <td>36.285714</td>\n    </tr>\n    <tr>\n      <th>177</th>\n      <td>4</td>\n      <td>137</td>\n      <td>34.250000</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>1309</th>\n      <td>15</td>\n      <td>443</td>\n      <td>34.076923</td>\n    </tr>\n    <tr>\n      <th>1314</th>\n      <td>12</td>\n      <td>508</td>\n      <td>42.333333</td>\n    </tr>\n    <tr>\n      <th>1317</th>\n      <td>18</td>\n      <td>1210</td>\n      <td>67.222222</td>\n    </tr>\n    <tr>\n      <th>1319</th>\n      <td>9</td>\n      <td>610</td>\n      <td>67.777778</td>\n    </tr>\n    <tr>\n      <th>1323</th>\n      <td>15</td>\n      <td>764</td>\n      <td>50.933333</td>\n    </tr>\n  </tbody>\n</table>\n<p>278 rows × 3 columns</p>\n</div>"
     },
     "metadata": {},
     "execution_count": 22
    }
   ],
   "source": [
    "data_gb.agg({'counts':np.sum,'amounts':[np.sum,np.mean]})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "counts       3088\namounts    125992\ndtype: int64"
     },
     "metadata": {},
     "execution_count": 23
    }
   ],
   "source": [
    "data[['counts','amounts']].apply(np.sum)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "counts       3088\namounts    125992\ndtype: int64"
     },
     "metadata": {},
     "execution_count": 24
    }
   ],
   "source": [
    "data[['counts','amounts']].agg(np.sum)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "output_type": "execute_result",
     "data": {
      "text/plain": "          counts  amounts\norder_id                 \n137            9      194\n165           21      953\n166            7      241\n171           10      254\n177            4      137\n...          ...      ...\n1309          15      443\n1314          12      508\n1317          18     1210\n1319           9      610\n1323          15      764\n\n[278 rows x 2 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>counts</th>\n      <th>amounts</th>\n    </tr>\n    <tr>\n      <th>order_id</th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>137</th>\n      <td>9</td>\n      <td>194</td>\n    </tr>\n    <tr>\n      <th>165</th>\n      <td>21</td>\n      <td>953</td>\n    </tr>\n    <tr>\n      <th>166</th>\n      <td>7</td>\n      <td>241</td>\n    </tr>\n    <tr>\n      <th>171</th>\n      <td>10</td>\n      <td>254</td>\n    </tr>\n    <tr>\n      <th>177</th>\n      <td>4</td>\n      <td>137</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>1309</th>\n      <td>15</td>\n      <td>443</td>\n    </tr>\n    <tr>\n      <th>1314</th>\n      <td>12</td>\n      <td>508</td>\n    </tr>\n    <tr>\n      <th>1317</th>\n      <td>18</td>\n      <td>1210</td>\n    </tr>\n    <tr>\n      <th>1319</th>\n      <td>9</td>\n      <td>610</td>\n    </tr>\n    <tr>\n      <th>1323</th>\n      <td>15</td>\n      <td>764</td>\n    </tr>\n  </tbody>\n</table>\n<p>278 rows × 2 columns</p>\n</div>"
     },
     "metadata": {},
     "execution_count": 25
    }
   ],
   "source": [
    "data_gb.apply(np.sum)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": "counts  amounts\n0       1     2401\n1       1     2304\n2       1      900\n3       1      625\n4       1      169\n   counts  amounts\n0       1       49\n1       1       48\n2       1       30\n3       1       25\n4       1       13\n"
    }
   ],
   "source": [
    "print(data[['counts','amounts']].transform(lambda x:x**2).head())\n",
    "print(data[['counts','amounts']].head())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "output_type": "error",
     "ename": "ZeroDivisionError",
     "evalue": "float division by zero",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mZeroDivisionError\u001b[0m                         Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-29-f4dc8dcfe178>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mdata_gb\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtransform\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;32mlambda\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmean\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m-\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmax\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m/\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmax\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m-\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmin\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32mF:\\Anaconda3\\lib\\site-packages\\pandas\\core\\groupby\\generic.py\u001b[0m in \u001b[0;36mtransform\u001b[1;34m(self, func, *args, **kwargs)\u001b[0m\n\u001b[0;32m   1415\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1416\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0misinstance\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfunc\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mstr\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1417\u001b[1;33m             \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_transform_general\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfunc\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1418\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1419\u001b[0m         \u001b[1;32melif\u001b[0m \u001b[0mfunc\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mbase\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtransform_kernel_whitelist\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mF:\\Anaconda3\\lib\\site-packages\\pandas\\core\\groupby\\generic.py\u001b[0m in \u001b[0;36m_transform_general\u001b[1;34m(self, func, *args, **kwargs)\u001b[0m\n\u001b[0;32m   1375\u001b[0m                     \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmsg\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1376\u001b[0m             \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1377\u001b[1;33m                 \u001b[0mres\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpath\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mgroup\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1378\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1379\u001b[0m             \u001b[1;32mif\u001b[0m \u001b[0misinstance\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mres\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mSeries\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mF:\\Anaconda3\\lib\\site-packages\\pandas\\core\\groupby\\generic.py\u001b[0m in \u001b[0;36m<lambda>\u001b[1;34m(group)\u001b[0m\n\u001b[0;32m   1474\u001b[0m             \u001b[0mfast_path\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mlambda\u001b[0m \u001b[0mgroup\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mfunc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mgroup\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1475\u001b[0m             slow_path = lambda group: group.apply(\n\u001b[1;32m-> 1476\u001b[1;33m                 \u001b[1;32mlambda\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mfunc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0maxis\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1477\u001b[0m             )\n\u001b[0;32m   1478\u001b[0m         \u001b[1;32mreturn\u001b[0m \u001b[0mfast_path\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mslow_path\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mF:\\Anaconda3\\lib\\site-packages\\pandas\\core\\frame.py\u001b[0m in \u001b[0;36mapply\u001b[1;34m(self, func, axis, raw, result_type, args, **kwds)\u001b[0m\n\u001b[0;32m   6876\u001b[0m             \u001b[0mkwds\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mkwds\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   6877\u001b[0m         )\n\u001b[1;32m-> 6878\u001b[1;33m         \u001b[1;32mreturn\u001b[0m \u001b[0mop\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_result\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   6879\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   6880\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0mapplymap\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfunc\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m->\u001b[0m \u001b[1;34m\"DataFrame\"\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mF:\\Anaconda3\\lib\\site-packages\\pandas\\core\\apply.py\u001b[0m in \u001b[0;36mget_result\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m    184\u001b[0m             \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mapply_raw\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    185\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 186\u001b[1;33m         \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mapply_standard\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    187\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    188\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0mapply_empty_result\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mF:\\Anaconda3\\lib\\site-packages\\pandas\\core\\apply.py\u001b[0m in \u001b[0;36mapply_standard\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m    311\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    312\u001b[0m         \u001b[1;31m# compute the result using the series generator\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 313\u001b[1;33m         \u001b[0mresults\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mres_index\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mapply_series_generator\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    314\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    315\u001b[0m         \u001b[1;31m# wrap results\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mF:\\Anaconda3\\lib\\site-packages\\pandas\\core\\apply.py\u001b[0m in \u001b[0;36mapply_series_generator\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m    339\u001b[0m         \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    340\u001b[0m             \u001b[1;32mfor\u001b[0m \u001b[0mi\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mv\u001b[0m \u001b[1;32min\u001b[0m \u001b[0menumerate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mseries_gen\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 341\u001b[1;33m                 \u001b[0mresults\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mf\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mv\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    342\u001b[0m                 \u001b[0mkeys\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mv\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mname\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    343\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mF:\\Anaconda3\\lib\\site-packages\\pandas\\core\\groupby\\generic.py\u001b[0m in \u001b[0;36m<lambda>\u001b[1;34m(x)\u001b[0m\n\u001b[0;32m   1474\u001b[0m             \u001b[0mfast_path\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;32mlambda\u001b[0m \u001b[0mgroup\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mfunc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mgroup\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1475\u001b[0m             slow_path = lambda group: group.apply(\n\u001b[1;32m-> 1476\u001b[1;33m                 \u001b[1;32mlambda\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mfunc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0maxis\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1477\u001b[0m             )\n\u001b[0;32m   1478\u001b[0m         \u001b[1;32mreturn\u001b[0m \u001b[0mfast_path\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mslow_path\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32m<ipython-input-29-f4dc8dcfe178>\u001b[0m in \u001b[0;36m<lambda>\u001b[1;34m(x)\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mdata_gb\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtransform\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;32mlambda\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmean\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m-\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmax\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m/\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmax\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m-\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mmin\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;31mZeroDivisionError\u001b[0m: float division by zero"
     ]
    }
   ],
   "source": [
    "data_gb.transform(lambda x:(x.mean()-x.max())/(x.max()-x.min()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ]
}